package com.tanhua.server.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.tanhua.server.mapper.QuestionMapper;
import com.tanhua.server.pojo.Question;
import com.tanhua.server.service.QuestionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * @author 西楚霸王
 * @date 2020/11/29 15:37
 */
@Service
public class QuestionServiceImpl implements QuestionService {


    @Autowired
    private QuestionMapper questionMapper;

    @Override
    public Question queryQuestion(Long userId) {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("user_id",userId);
        return this.questionMapper.selectOne(queryWrapper);
    }

    @Override
    public void save(Long userId, String content) {
        //判断问题是否存在，如果存在，进行修改，如果不存在，就新增操作
        Question question = this.queryQuestion(userId);
        if (null != question){
            question.setTxt(content);
            this.questionMapper.updateById(question);
        }else {
            question = new Question();
            question.setUserId(userId);
            question.setTxt(content);

            this.questionMapper.insert(question);
        }
    }
}
